﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;

namespace Fis.Win.Utils
{
    public class NavBarRegistry
    {
        readonly Dictionary<string, System.Windows.Forms.UserControl> registry = new Dictionary<string, System.Windows.Forms.UserControl>();

        public void Initialize(DevExpress.XtraNavBar.NavBarControl bar)
        {
            var data = UIUtils.ViewConfig.Tables["map"];

            foreach (var i in data.AsEnumerable())
            {
                var item = new DevExpress.XtraNavBar.NavBarItem { Name = i["key"].ToString(), Caption = i["caption"].ToString(), LargeImageIndex = 2, Tag = Agile.Engine.Utils.ReflectUtils.Instance(i["control"].ToString()) };
                item.LinkClicked += (sender, e) =>
                {
                    var c = ((sender) as DevExpress.XtraNavBar.NavBarItem).Tag as System.Windows.Forms.UserControl;
                    UIUtils.MainForm.SetMainControl(c);
                };

                bar.Items.Add(item);
                bar.ActiveGroup.ItemLinks.Add(item);
                registry.Add(item.Name, item.Tag as System.Windows.Forms.UserControl);

            }

        }

        public void SetNavbarState()
        {
            UIUtils.MainForm.SetMainControl(registry["system"]);
        }

    }
}
